package com.ly.nethub.config


const val CODE_UNINITIALIZED = -1
const val CODE_CONNECTED = 10000
const val CODE_UNCONNECTED = 10001
const val CODE_CONNECTING = 10003
const val CODE_CONNECT_FAILED = -10000
const val CODE_CONNECT_FAILED_CLOSED = -10001
const val CODE_CONNECT_FAILED_SERVER_LIST_EMPTY = -10002
const val CODE_CONNECT_FAILED_SERVER_ILLEGITIMATE = -10004
const val CODE_CONNECT_FAILED_NETWORK_UNAVAILABLE = -10005
const val CODE_TASK_TIME_OUT = -10006
const val CODE_TASK_CANCEL = -10007
const val CODE_TASK_SEND_FAILED = -10008
const val CODE_RESP_PARSE_FAILED = -10009
const val CODE_TASK_SEND_SUCCESS = 1

object NetHubErrorMsg {
    private val map = mapOf(
        CODE_UNINITIALIZED to "连接组件未初始化",
        CODE_UNCONNECTED to "未连接",
        CODE_CONNECTING to "连接中",
        CODE_CONNECTED to "连接成功",
        CODE_CONNECT_FAILED to "连接失败",
        CODE_CONNECT_FAILED_CLOSED to "连接已关闭",
        CODE_CONNECT_FAILED_SERVER_LIST_EMPTY to "服务器地址列表为空",
        CODE_CONNECT_FAILED_SERVER_ILLEGITIMATE to "服务器地址不合法",
        CODE_CONNECT_FAILED_NETWORK_UNAVAILABLE to "网络不可用",
        CODE_TASK_TIME_OUT to "任务超时",
        CODE_TASK_CANCEL to "任务已取消",
        CODE_TASK_SEND_FAILED to "任务请求失败",
        CODE_RESP_PARSE_FAILED to "数据解析失败",
        CODE_TASK_SEND_SUCCESS to "操作成功"
    )

    operator fun get(key: Int): String = map[key] ?: ""
}

fun Int.findMsg(): String = NetHubErrorMsg[this]